package com.xmkj.bearuser.sort;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.xmkj.bearuser.R;

import java.util.List;

/**
 * Created by Administrator on 2017/10/26.
 */

public class MyAdapter extends BaseAdapter {
    private Context context;
    private List<String> strings;
    public static int mPosition;

    public MyAdapter(Context context, List<String> strings){
        this.context =context;
        this.strings = strings;
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return strings.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return strings.get(position);
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder  viewHolder=new ViewHolder();
        if(convertView==null){
            convertView = LayoutInflater.from(context).inflate(R.layout.listview_item, null);
            viewHolder.tv=(TextView) convertView.findViewById(R.id.tv);
            mPosition = position;
            viewHolder.tv.setText(strings.get(position));
            if (position == SortDetailsFrament.mPosition) {
//                convertView.setBackgroundResource(R.drawable.tv_next);
                viewHolder.tv.setTextColor(Color.parseColor("#EB728C"));
            } else {
                viewHolder.tv.setTextColor(Color.parseColor("#000000"));
                convertView.setBackgroundColor(Color.parseColor("#ffffff"));
            }
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tv.setText(strings.get(position));
        if (position == SortDetailsFrament.mPosition) {
//            convertView.setBackgroundResource(R.drawable.tv_next);
            viewHolder.tv.setTextColor(Color.parseColor("#EB728C"));
        } else {
            viewHolder.tv.setTextColor(Color.parseColor("#000000"));
            convertView.setBackgroundColor(Color.parseColor("#ffffff"));
        }
        return convertView;
    }

    private static class ViewHolder
    {
        TextView tv;
    }
}
